package com.zhuangjie.rider.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhuangjie.order.pojo.RiderDeliveryFeeForRiderOrderAccounting;
import com.zhuangjie.rider.dto.NearbyDeliveryOrderQueryDTO;
import com.zhuangjie.rider.entity.DeliveryOrder;
import com.zhuangjie.rider.pojo.DeliveryOrderInfoForNoticeUser;
import com.zhuangjie.rider.pojo.RechargeableDeliveryOrderGenericQueryCondition;
import com.zhuangjie.rider.vo.CompletedQuantityStatisticsVO;
import com.zhuangjie.rider.vo.DeliveryOrderForUserOrderMapVO;
import com.zhuangjie.rider.vo.NearbyDeliveryOrder;
import com.zhuangjie.rider.vo.WaitPickingDeliveryOrder;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zhuangjie
 * @since 2023-12-26
 */
//@Mapper
public interface DeliveryOrderMapper extends BaseMapper<DeliveryOrder> {

    Page<NearbyDeliveryOrder> findNearbyDeliveryOrders(@Param("params") NearbyDeliveryOrderQueryDTO nearbyDeliveryOrderQueryDTO,@Param("generic_query_condition") RechargeableDeliveryOrderGenericQueryCondition genericQueryCondition, Page<NearbyDeliveryOrder> nearbyDeliveryOrdersPage);

    Page<WaitPickingDeliveryOrder> queryRiderWaitPickingDeliverOrders(@Param("page") Page<WaitPickingDeliveryOrder> page, @Param("riderId") Long riderId, @Param("beginDeliveryState") int beginDeliveryState, @Param("endDeliveryState") int endDeliveryState);

    Page<DeliveryOrder> queryRiderWaitDeliveryPage(@Param("page") Page<DeliveryOrder> page, @Param("riderId") Long riderId, @Param("deliveryState") int deliveryState);

    /**
     * 注意这里查的只有DeliveryOrder的字段，而NearbyDeliveryOrder特有的字段需要后面计算
     * @param deliveryOrderId
     * @return
     */
    NearbyDeliveryOrder selectToNearbyDeliveryOrderById(@Param("deliveryOrderId") Long deliveryOrderId);

    RiderDeliveryFeeForRiderOrderAccounting queryRiderDeliveryFeeForRiderOrderAccounting(@Param("orderId") Long orderId);

    CompletedQuantityStatisticsVO completedQuantityStatistics(@Param("riderId") Long riderId, @Param("deliveryCompletedState") int deliveryCompletedState, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

    DeliveryOrderForUserOrderMapVO selectDeliveryInfoForUserOrderMap(@Param("orderId") Long orderId);

    DeliveryOrderInfoForNoticeUser getDeliveryOrderInfoForNoticeUser(@Param("deliveryOrderId") Long deliveryOrderId);

    /**
     *
     * @param riderId 骑手id
     * @param riderReceivedDeliveryState     骑手已接单状态
     * @return riderPickedUpDeliveryOrderIds 骑手已取餐状态
     */
    List<Long> queryRiderUnfinishedDeliveryOrderUserIds(@Param("riderId") Long riderId, @Param("riderReceivedDeliveryState") int riderReceivedDeliveryState, @Param("riderPickedUpDeliveryState") int riderPickedUpDeliveryState);
}
